module.exports = function($scope, $modal, $resource, getDate, toaster){

    $scope.search= function(){
        $scope.searchform.tour_date = getDate($scope.searchform.tour_date);
        $scope.total.booked = 0;
        $scope.total.self = 0;
        $scope.total.tour = 0;
        $resource('/api/as/ggc/order/getOrderAccountList', {}, {}).save($scope.searchform, function (res) {
            if (res.errcode === 0){
                $scope.result_list = res.data;
                angular.forEach(res.data, function(item){
                    $scope.total.booked += item.booked;
                    $scope.total.self += item.self;
                    $scope.total.tour += item.tour;
                });
            } else {
                toaster.error({title: '', body: '统计失败, 请重试'});
            }
        });
    }

    init();
    function init(){
        $scope.searchform = {
            'usedate': 0,
            'tour_date': getDate(new Date()),
            'opened': false
        };
        $scope.total = {};
        $scope.search();
        $resource('/api/as/ggc/activity/forSearchList', {}, {}).save({}, function (res) {
            if (res.errcode === 0){
                $scope.activity_list = res.data;
                $scope.activity_list.unshift({'title': '全部', 'activity_id': undefined});
            } else {
                toaster.error({title: '', body: '查询公益游列表失败'});
            }
        });
    }
    
    //打开日历空间,选择时间
    $scope.dateOpen = function ($event, item) {
        $event.preventDefault();
        $event.stopPropagation();
        item.opened = true;
    };

};